#!/bin/sh

LOGS=/logs/current
DATE=`date +%Y_%m_%d`

touch $LOGS/creating/1
/sbin/mtx first

/sbin/mtx status | grep "Data Transfer Element 0" | awk '{print $NF}' >> $LOGS/tapes.log

if [ foo$1 = "fooweekly" ]
then
  AFTER_DATE=`date --date="-1 month" +"28 %B %Y"`
  /bin/tar cfvMVF /dev/nst0 "Weekly incremental backup started on $DATE relative to $AFTER_DATE" /usr/local/bin/yz_change_create_tape.sh --after-date "$AFTER_DATE" USA_DB usa usadata000 FROG
elif [ foo$1 = "foodaily" ]
then
  AFTER_DATE=`date --date="last Friday"`
  /bin/tar cfvMVF /dev/nst0 "Daily incremental backup started on $DATE relative to $AFTER_DATE" /usr/local/bin/yz_change_create_tape.sh --after-date "$AFTER_DATE" USA_DB usa usadata000 FROG
else
  /bin/tar cfvMVF /dev/nst0 "Full backup started on $DATE" /usr/local/bin/yz_change_create_tape.sh USA_DB usa usadata000 FROG
fi

TAPENUM=`ls $LOGS/creating`
/sbin/mtx unload $TAPENUM 0
mv $LOGS/creating/$TAPENUM $LOGS/done_create

echo Done

